package com.scb.api.resource;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.scb.api.entity.User;
import com.scb.api.service.UserService;

@Component
@Path("/users")
@Scope("request")
public class UserResource {
	
	private static final Logger log = Logger.getLogger(UserResource.class);
	
	@Autowired
	UserService userService;
	
	@GET 
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Path("/showall")
    public List<User> getAllUsers() {
		
		log.info("Requested: /users/showall");
		
		return userService.getAll();
	}
	
	@GET 
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Path("{userid: [0-9]}")
    public User findUserById(@PathParam("userid") Long userid) {
		
		log.info("Requested: /users/findUserById/" + userid);
		
		return userService.getUserById(userid);
	}
}
